package cn.jussi.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;

import cn.jussi.model.User;

@WebServlet(urlPatterns= {"/userController"})
public class userController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//System.out.println("表单已提交");
		
		/**
		 * 这样太繁琐
		 */
		/*String username = req.getParameter("username");
		String pasword = req.getParameter("pasword");
		String[] hobby = req.getParameterValues("hobby");
		
		User user = new User();
		
		user.setUsername(username);
		user.setPasword(pasword);
		user.setHobby(hobby);*/
		
		User user = new User();
		System.out.println("分装前的user:"+user);
		try {
			BeanUtils.populate(user, req.getParameterMap());
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("分装后的user:"+user);
	}
}
